#coding=utf-8
import xml.dom.minidom
import os
import argparse

class Case:
    test = None
    result = None

# 打开xml文档
def getCase(path):
    caseList = []
    from xml.etree import ElementTree as ET
    per=ET.parse(path)
    p=per.findall('./case')
   
    # 得到文档元素对象
    for oneper in p:
        case = Case()
        for child in oneper.getchildren():
            #print child.tag,':',child.text
            if child.tag == "test":
                case.test = child.text.strip()
            elif child.tag == "result":
                case.result = child.text.strip()
        caseList.append(case)
    print caseList
    return caseList
    
# 运行获取到的命令
def execute(allCase):
    for case in allCase:
        command = str(case.test).strip()
        r = os.popen(command)
        lines = str(r.readlines()[0]).strip()
        print "lines: " + lines
        if lines ==  case.result:
            print "is right"
        else:
            print "is wrong"
            print "expected \"%s\", actual \"%s\"" % ( case.result, lines)
        
#主函数
if __name__ == '__main__':
    execute(getCase('usecase.xml'))